#ifndef NETWINDOW_H
#define NETWINDOW_H

#include <QMainWindow>
#include <QSplitter>
#include "GameWidget.h"
#include <QMenu>
#include <QMenuBar>
#include <QToolBar>
#include <QAction>
#include <QTimer>
#include "PlayerWidget.h"
#include "TalkWidget.h"

class NetWindow : public QMainWindow
{
    Q_OBJECT
    enum Status{
        DISCONNECTED,
        LOGIN,
        NEWGAME,
        JOINROOM,
        LOOK,
        INGAME
    };

    GameWidget mGameWidget;
    PlayerWidget mPlayerWidget;
    TalkWidget mTalkWidget;
    QTcpSocket& mSocket;
    Status mStatus;
    QString mClientID;
    QString pwd;
    int mRoomID;
    int mFoodCount;
    int mGameTime;
    QList<int> mRoomList;
    Protocol::DataType mLastProtocol;
    //bool mIsRoomOwner;

    QAction* mNewGameAction;
    QAction* mJoinGameAction;
    QAction* mExitGameAction;
    QAction* mStartAction;
    QAction* mPauseAction;
    QAction* mStopAction;

    bool initCentralWidget();
    bool initMenuBar();
    bool initGameMenu(QMenuBar *mb);
    bool initSetMenu(QMenuBar* mb);
    //bool initWindowMenu(QMenuBar* mb);
    bool initAboutMenu(QMenuBar *mb);
    QAction* makeAction(QObject* parent, const QString& string, const QKeySequence& shortcut);

    bool initToolBar();
    bool exit_game();

    void moveToCentral(int x, int y);

public:
    explicit NetWindow(QTcpSocket& socket, QString username, QString pwd, QWidget *parent = 0);
    ~NetWindow();
    
signals:
    void update_widget();

protected slots:
    void onNewGameClicked();
    void onJoinGameClicked();
    void onExitGameClicked();
    void onChangeModeClicked();
    void onExitClicked();
    void onNetGameSetClicked();
    void onAboutClicked();
    void onStartClicked();
    void onPauseClicked();
    void onStopClicked();

    void connected();
    void disconnected();
    void writeSocket(const QByteArray& buf);

    void sendTalk(QString msg);
public slots:
    void readData();
};

#endif // NETWINDOW_H
